package com.example.yls.demoa;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Point;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
private Button btn11;
private Button btn1;
private Button btn2;
private Button btn3;
private Button btn4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btn11Event();
        btn1Event();
        btn2Event();
        btn3Event();
        btn4Event();
    }
    private void btn4Event() {
          btn4.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {

                  ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(btn11,
                          "Alpha",1,0);
                  objectAnimator.setDuration(3000);
                  objectAnimator.setRepeatCount(2);
                  objectAnimator.start();

              }
          });
    }
    private void btn3Event() {
          btn3.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(btn11,
                          "rotation",0,360);
                  objectAnimator.setDuration(3000);
                  objectAnimator.setRepeatCount(2);
                  objectAnimator.start();

              }
          });
    }
    private void btn2Event() {
              btn2.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(btn11,
                              "scaleX",1,5);
                      objectAnimator.setDuration(3000);
                      objectAnimator.setRepeatCount(2);
                      objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                          @Override
                          public void onAnimationUpdate(ValueAnimator valueAnimator) {
                              float value= (float) valueAnimator.getAnimatedValue();
                              btn11.setScaleY(value);
                          }
                      });
                      objectAnimator.start();
                  }
              });
    }

    private void btn1Event() {
                    btn1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                            float currentX=btn11.getTranslationX();
                            ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(btn11,
                                    "translationX",currentX,500);
                            objectAnimator.setDuration(3000);
                            objectAnimator.setRepeatCount(2);
                            objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                                @Override
                                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                                    float value= (float) valueAnimator.getAnimatedValue();
                                    btn11.setTranslationY(value);
                                }
                            });
                            objectAnimator.start();
                        }
                    });

    }
    private void btn11Event() {
       btn11.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {

               point start=new point(100,100);
               point end=new point(400,600);
               ValueAnimator valueAnimator=ValueAnimator.ofObject(new PointEvaluator(),
                      start,end );

               valueAnimator.setDuration(3000);
               valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                   @Override
                   public void onAnimationUpdate(ValueAnimator valueAnimator) {
                   point point= (com.example.yls.demoa.point) valueAnimator.getAnimatedValue();
                     btn11.setTranslationX(point.getX());
                     btn11.setTranslationY(point.getY());
                     btn11.requestLayout();
                   }
               });
               valueAnimator.start();
           }
       });

    }

    private void initView() {
                  btn11=findViewById(R.id.btn11);
                  btn1=findViewById(R.id.btn1);
                  btn2=findViewById(R.id.btn2);
                  btn3=findViewById(R.id.btn3);
                  btn4=findViewById(R.id.btn4);

    }
}
